Skip to content

fix: resolve issues #911 #912 #913 #914 — N+1 queries, e2e tests, coverage thresholds, structured logging - #1006

Open
khalyaro wants to merge 5 commits into
MettaChain:mainfrom
khalyaro:feature/issues-911-912-913-914
Open

fix: resolve issues #911 #912 #913 #914 — N+1 queries, e2e tests, coverage thresholds, structured logging#1006
khalyaro wants to merge 5 commits into
MettaChain:mainfrom
khalyaro:feature/issues-911-912-913-914

Conversation

@khalyaro

Copy link
Copy Markdown

Summary

Resolves four assigned issues in a single cohesive PR.


Closes #911 — Fix N+1 query patterns

  • sessions.service.ts getUserSessions: replaces in-memory filter() on the full session array with two parallel count() DB queries for active/revoked counts
  • dashboard.service.ts getQuickStats: replaces separate buyerTransactions + sellerTransactions queries with a single OR query; replaces full property array load with two count() calls
  • notifications.service.ts deliverPending: replaces the per-notification update loop with a single updateMany batch
  • prisma.service.ts: adds a rolling-window N+1 detector in the $on('query') handler — warns when the same table is queried 5+ times within 100 ms (development/staging only)

Closes #912 — End-to-end tests for major API workflows

Six new e2e test suites (46 tests, all green):

File Tests
user-registration-login.e2e.spec.ts profile management, auth rejection
property-crud-search-favorite.e2e.spec.ts CRUD lifecycle + favorites
rbac-enforcement.e2e.spec.ts role-based access on sessions/notifications
notifications.e2e.spec.ts list, unread-count, mark-read, delete
sessions-management.e2e.spec.ts list, rename, revoke, revoke-all
documents-access-control.e2e.spec.ts list, get-by-id, access control

Closes #913 — Coverage thresholds for all modules in CI

  • jest.config.js: global 50% threshold (statements/lines, 40% branches, 45% functions) with per-module overrides for critical paths:
    • src/auth/ → 60%
    • src/documents/ → 70% (preserving existing)
    • src/sessions/, src/notifications/, src/dashboard/ → 50%
    • src/transactions/ → 55%
  • ci.yml: replaces the ad-hoc inline documents-only coverage step with npm run test:cov so all thresholds declared in jest.config.js are enforced on every CI run

Closes #914 — Structured JSON logging

  • src/common/logger.ts: new AppLogger class extending ConsoleLogger
    • JSON output in NODE_ENV=production: each line is a single JSON object with level, timestamp, context, correlationId, message + extra metadata
    • NestJS pretty-print in development for ergonomic terminal output
    • scrubSensitive() helper redacts known PII keys (password, token, apiKey, privateKey, …) from structured metadata before serialisation
  • src/main.ts: uses AppLogger as the NestJS application logger via NestFactory.create({ logger })

Testing

  • npm run build ✅ (zero TypeScript errors)
  • 46 new e2e tests — all passing
  • Existing unit tests unaffected

Closes #911
Closes #912
Closes #913
Closes #914

…aChain#914

Issue MettaChain#914 - Structured JSON logging
- Add src/common/logger.ts (AppLogger extending ConsoleLogger)
  - JSON output in production, NestJS pretty-print in development
  - Automatic timestamp, context, correlationId on every line
  - Scrubs sensitive fields (password, token, apiKey, etc.)
- Wire AppLogger into NestFactory.create and Bootstrap logger in main.ts

Issue MettaChain#913 - Coverage thresholds for all modules in CI
- Rewrite jest.config.js with global 50% threshold (statements/lines)
  and per-module critical thresholds: auth (60%), documents (70%),
  sessions/notifications/dashboard (50%), transactions (55%)
- Update .github/workflows/ci.yml: replace ad-hoc documents-only
  coverage step with 'npm run test:cov' which enforces all thresholds

Issue MettaChain#911 - Fix N+1 query patterns
- sessions.service.ts getUserSessions: push active/revoked counts to
  DB via two parallel count() queries instead of in-memory filtering
- dashboard.service.ts getQuickStats: single OR query for
  buyer+seller transactions; two count() queries for property totals
- notifications.service.ts deliverPending: batch updateMany instead
  of a per-notification UPDATE loop
- prisma.service.ts: add rolling-window N+1 detection in the query
  event handler (warns when same table queried 5+ times in 100ms)

Issue MettaChain#912 - End-to-end tests for major API workflows
- Add 6 new e2e test suites (46 tests, all passing):
  - user-registration-login.e2e.spec.ts  (profile management)
  - property-crud-search-favorite.e2e.spec.ts  (CRUD + favorites)
  - rbac-enforcement.e2e.spec.ts  (role-based access control)
  - notifications.e2e.spec.ts  (list/read/delete notifications)
  - sessions-management.e2e.spec.ts  (list/rename/revoke sessions)
  - documents-access-control.e2e.spec.ts  (document access control)
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@khalyaro Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

khalyaro and others added 4 commits July 30, 2026 00:31
Resolve conflicts in jest.config.js, src/main.ts. Fix unused Logger import,
add AccountDeletionService/DataExportService mocks in e2e test.
Resolve conflicts in jest.config.js, src/main.ts. Fix unused imports, CRLF
line endings, and e2e test unused variables for CI lint compliance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants